PNG Utilities Plugin v1.6.1 for REALbasic 5.x (formerly LoadSavePNG) Method Reference
Written by Frank Condello with contributions by Will Leshner and Jonathan Johnson.
Feedback: developer@chaoticbox.com
Web: http://developer.chaoticbox.com/

Portions from LoadSaveJPEG Copyright (c) 2001 Dair Grant and Copyright (c) 2003 Joe Strout

zlib Copyright (c) 1995-2002 Jean-loup Gailly and Mark Adler

libpng Copyright (c) 1998-2002 Glenn Randers-Pehrson

About
The PNG Utilities Plugin allows easy loading and saving of PNG format images from within REALbasic. The plugin automatically converts picture masks into PNG alpha channels and vice-versa, allowing developers to load or save masked images with a single function call. In addition to storing alpha information, the PNG format allows for true-colour images and uses efficient lossless compression, making PNG files ideal when smaller file sizes are desired but without sacrificing image fidelity or transparency information. For more information on the PNG format, see the Basic Introduction to PNG Features.

The PNG Utilities Plugin supports Mac OS 8/9 (Classic/Carbon), Mac OS X (PEF/Macho), Win32, and Linux. PNG Utilities is opensource and free to use and modify. Please see the LICENSE.txt file in the source distribution for more information.

Usage Notes
Place the PNG Utilities Plugin.rbx file included in the download into your REALbasic plugin folder and launch REALbasic. The plugin provides a PNGu module in REALbasic 5.5 or later, and global methods prefixed with PNGu in previous versions. Please read the method reference document and see the included example projects for more detailed information.

NOTE: If you use Photoshop to create PNG files, do yourself a favour and download the free SuperPNG Photoshop plugin (available for both Mac OS and Windows).

Problems / Limitations / Quirks:
IMPORTANT: Linux builds dynamically link with libpng and zlib at runtime. PNG Utilities will not function without these libraries, but they are typically included with Linux distributions and no extra installation will be required under normal circumstances. Mac and Win32 builds are self-contained (i.e. statically linked libpng and zlib libraries are built into the application itself).

The goal from the get-go was to keep the plugin simple, free, and opensourced. If you need more comprehensive PNG support, please check out Micono RbPNGLib.

PNG Utilities can load any valid PNG file (true-colour, palletted, greyscale, etc.) but currently only saves true-colour RGB and RGBA formats.

Omitting the gamma value when loading a PNG will cause the loader to first check the file for an embedded value, and then settle for the default value for the current system (1.8 on MacOS, 2.2 on Win32/Linux). Omitting a gamma value when saving will also embed the system default. To retrieve raw RGB data regardless of embedded gamma, always use the native screen gamma for each operating system, or use a value of -1.0 to have PNG utilities do this for you automatically.

When loading a PNG image, the gamma is applied destructively. This means that the original RGB data no longer exists, and only the gamma-corrected RGB values are returned and stored in the REALbasic Picture object. Therefore, if you open a PNG using a non-native gamma value, and then re-save the image, the resulting PNG will not match the original.

Masks in RB treat black as opaque, while alpha channels treat white as opaque. The plugin automatically inverts masks into alphas, and alphas into masks, but you should be aware of this behaviour.

Version History
v1.6.1 - October 25 2004

- Linux support (Jonathan Johnson).


v1.5.2 - Septmenber 17 2004

- Updated to libpng version 1.2.7 which fixes a save bug that causes some programs to incorrectly read in the resulting image (i.e. any application that uses Microsoft's PNG loader on Win32).

- Updated zlib to version 1.2.1 (minor memory savings, and possible speed ups).

- Renamed the Win32 DLL to avoid potential conflicts with other plugins.


v1.5.1 - August 18 2004

- Updated libpng to version 1.2.6 which addresses several vulnerabilities found in libpng 1.2.5.


v1.5 - July 9 2004

- Added a "GetData" method (Will Leshner).

- Fixed several potential memory leaks if a save or load function bails due to a library or file/buffer error.

- PNG files saved on Mac OS X now set their creator to "????" allowing Launch Services to resolve the application.

- More and better error checking, plus other minor code clean-ups.


v1.4 - July 6 2004

- The external module is no longer needed. The plugin now contains all functionality internally.

- The "*AndMask" methods have been removed as a result of the change above (redundant).

- All methods renamed for better integration with RB 5.5 namespace features.

- Fixed a potential object leak in the Win32 save routines.

- Using a gamma of -1.0 in the loading methods will force the current system gamma. This can be used to get raw RGB colour on any system without requiring specific knowledge about the native gamma values.

- Changed name to "PNG Utilities" since the plugin is incompatible with projects built with the old LoadSavePNG plugin.


v1.3 (LoadSavePNG) - October 14 2003

- Indexed-colour PNGs with 1bit transparency now load properly.


v1.2 (LoadSavePNG) - September 15 2003

- Added methods to generate a picture object from PNG data stored in a string.

- Files are properly closed after loading.


v1.1 (LoadSavePNG) - August 28 2003

- grayscale PNGs with a depth of less than 8 bits now load properly.


v1.0 (LoadSavePNG) - July 24 2003

- Initial release.

Method Reference